﻿using System.Windows;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCommon;
using System;
using Baosight.ZNH.ZMCommon.ChildWindows;

namespace Baosight.ZNH.ZMCC.UI.ChildWindows
{
    /// <summary>
    /// 质量标准化
    /// 分项管理的新增、修改、查看页面
    /// 对应后台ServiceZMCS02.java
    /// @author 严洪浩
    /// </summary>
    public partial class QualityStandardSubItem : EFViewCmes
    {

        public QualityStandardSubItem(string dialogType)
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
            Init(dialogType);
        }

        /// <summary>
        /// 初始化父类EFViewCmesProperty的值，每次点击“确定”、“返回”时执行此方法，从新赋值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.spWindows.GetChildObjects<EFDataField>(null, true);
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 初始化页面数据
        /// </summary>
        private void Init(string type)
        {
            type = type == null ? "insert" : type.ToLower();

            switch (type)
            {
                case "insert":
                    this.fdPointMethod.Value = "分值";
                    this.fdPointValue.Value = "1";
                    this.fdPointValue.IsReadOnly = true;
                    base.Mode = OperationMode.Insert;
                    break;
                case "update":
                    base.Mode = OperationMode.Update;
                    break;
                case "detail":
                    this.Commit.Visibility = Visibility.Collapsed;
                    BaseTools.EFDataFieldNotEnabled(this.spWindows.GetChildObjects<EFDataField>(null, true));
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommitClick(object sender, RoutedEventArgs e)
        {
            base.OnCommitButtonClick("ZMCC01", sender, e);
        }

        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelClick(object sender, RoutedEventArgs e)
        {
            CmesWindows _window = this.Parent as CmesWindows;
            _window.DialogResult = false;
            _window.Close();
        }

        /// <summary>
        /// 下拉框数据改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdPointMethod_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            if (e.NewValue != null)
            {
                string _value = e.NewValue as string;
                if (_value.Equals("分值"))
                {
                    this.fdPointValue.IsReadOnly = true;
                    this.fdPointValue.Value = "1";
                }
                else
                {
                    this.fdPointValue.IsReadOnly = false;
                }
            }
        }
    }
}

